// pages/Balance/Balance.js
const app = getApp();
const util = require('../../../utils/util.js')
const http = require('../../../utils/http.js');
Page({
  onAgreement() {
    wx.navigateTo({
      url: '/pages/onNewPages/agreement/agreement?url=' + 'cashQuestion',
    })
  },
  data: {

    noncestr: '',
    balance: '',
    showModalStatus: false
  },
  back() {
    // let ban = getApp().ban;
    // if(ban == 1){
    wx.switchTab({
      url: '../UserCenter/userCenter',
    })
  },
  //跳转h5页面
  getH5(e) {
    let h5 = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: '/pages/onNewPages/Webview/Webview?h5=' + h5,
    })
  },
  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  //提现跳转
  deposit: function (e) {
    let token = wx.getStorageSync('token');
    if (token) {
      // let forward = e.target.dataset.forward;
      if (this.data.list.length > 1) {
        this.setData({
          showModalStatus: true
        })
      } else {
        wx.redirectTo({
          // url: '../Deposit/Deposit?jump=' + jump,
          url: '/pages/Login/Deposit/Deposit?jump=' + 1,
        })
      }
    } else {
      wx.navigateTo({
        url: '/pages/onNewPages/Accredit/Accredit',
      })
    }

  },
  //跳转h5
  hideModal() {
    this.setData({
      showModalStatus: false
    })
  },
  Choose(e) {
    this.setData({
      showModalStatus: false
    })
    let jump = e.currentTarget.dataset.jump;
    wx.navigateTo({
      url: '/pages/Login/Deposit/Deposit?jump=' + jump,
    })
  },
  //银行卡跳转
  bankCard() {
    let token = wx.getStorageSync('token');
    if (token) {
      wx.navigateTo({
        url: '/pages/Login/BankCard/BankCard',
      })
    } else {
      wx.navigateTo({
        url: '/pages/onNewPages/Accredit/Accredit',
      })
    }
  },
  //跳转充值
  recharge: function () {
    let content = wx.getStorageSync('content');
    if (content) {
      wx.navigateTo({
        url: '/pages/onNewPages/Recharge/Recharge',
      })
    } else {
      wx.navigateTo({
        url: '/pages/onNewPages/Accredit/Accredit',
      })
    }

  },
  //账户详情 跳转
  toBill() {
    wx.navigateTo({
      url: '/pages/Login/Bill/Bill',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},
  finance(data) {
    this.setData({
      isShow: true
    })
    var _this = this;
    http.getRequest('v1/finance', data,
      function (res) {
        console.log(res)
        if (res.code != 200) {
          wx.navigateTo({
            url: '/pages/Login/Index/index'
          })
        }
        _this.setData({
          balance: res.data.money,
          list: res.data.apply,
          answers: res.data.answers,
          forward_count: res.data.forward_count,
          state: res.data.content
        })
      },
      function (err) {
        wx.navigateTo({
          url: '/pages/Login/Index/index'
        })
      })
  },
  onReady: function () {},
  onShow: function () {
    this.finance()
  },
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {}
})